﻿using System;
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using EmbeddedSharp.Scripting;

namespace Zove.Runtime.Test {
    [TestClass]
    public class ListTests : AbstractTests {
        [TestMethod]
        public void NewList() {
            IContext cnt = Execute("a=[1,2,3]");

            object value = cnt.GetVariable("a");
            Assert.IsInstanceOfType(value, typeof(List<object>));

            List<object> lst = value as List<object>;
            Assert.AreEqual(3, lst.Count);
            Assert.AreEqual(1, Convert.ToDouble(lst[0]));
            Assert.AreEqual(2, Convert.ToDouble(lst[1]));
            Assert.AreEqual(3, Convert.ToDouble(lst[2]));
        }

        [TestMethod]
        public void JoinList() {
            IContext cnt = Execute(
                "a=[1,2,3];b=[4,5,6];c=join(a,b);");

            object value = cnt.GetVariable("c");
            Assert.IsInstanceOfType(value, typeof(List<object>));

            List<object> lst = value as List<object>;
            Assert.AreEqual(6, lst.Count);
            Assert.AreEqual(1, Convert.ToDouble(lst[0]));
            Assert.AreEqual(2, Convert.ToDouble(lst[1]));
            Assert.AreEqual(4, Convert.ToDouble(lst[3]));
        }

        [TestMethod]
        public void TestPick() {
            IContext cnt = Execute(
                "a=[1,2,3];b=pick(a, 2);");

            double value = Convert.ToDouble(
                cnt.GetVariable("b"));
            Assert.AreEqual(3, value);
        }

        [TestMethod]
        public void TestUnion() {
        }
    }
}
